import { SkillListPanel } from "../SkillListPanel";
import { SkillRuneItem } from "./SkillRuneItem";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SkillRuneEvent } from "./SkillRuneEvent";
import { LadderBattlefieldUtil } from "../../ladderBattlefield/LadderBattlefieldUtil";
import { LadderCareerConfig } from "../../../resource/LadderCareerConfig";
import { Cache } from "../../../cache/Cache";
import { SPlayerRuneInfo } from "../../../../../Message/Game/SPlayerRuneInfo";
import { ERuneType } from "../../../../../Message/Public/ERuneType";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class SkillRuneMapPanel
    
    export  class SkillRuneMapPanel extends SkillListPanel
    {
        constructor()
        {
            super();
            this._vcSkillRune = new Vector.<SkillRuneItem>();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            this.updateRuneData();
            return;
        }

        protected /* override */ initUI(): void
        {
            _bgBmp = new Object /* flash.display.Bitmap */();
            addChild(_bgBmp);
            LoaderHelp.setBitmapdata("skillListRuneBg.swf", _bgBmp);
            var loc1=ObjCreate.createTextField("", 25, 5, 200, 20, this);
            loc1.htmlText = Language.getString(44057);
            this._generalRune1 = this.createRuneItem(35, 39, 1);
            this._generalRune2 = this.createRuneItem(185, 39, 2);
            this._generalRune3 = this.createRuneItem(35, 317, 3, true);
            this._generalRune4 = this.createRuneItem(185, 317, 4, true);
            this._skillRune1 = this.createRuneItem(112, 92, 5);
            this._skillRune2 = this.createRuneItem(175, 116, 6);
            this._skillRune3 = this.createRuneItem(198, 181, 7);
            this._skillRune4 = this.createRuneItem(177, 247, 8);
            this._skillRune5 = this.createRuneItem(111, 267, 9, true);
            this._skillRune6 = this.createRuneItem(44, 247, 10, true);
            this._skillRune7 = this.createRuneItem(25, 180, 11, true);
            this._skillRune8 = this.createRuneItem(48, 115, 12, true);
            this._btnSkillHandbook = ObjCreate.createGLoadedButton(ResFileConst.SkillRuneHandbookBtn, 90, 160, 75, 76, this);
            LoaderHelp.addResCallBack(ResFileConst.rune, this.onRuneCompl);
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDblClick);
            this._btnSkillHandbook.addEventListener(flash.events.MouseEvent.CLICK, this.showHandbookHandler);
            return;
        }

        /* internal  */onDblClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (typeof arg1.target === "skillruneitem") 
            {
                loc1 = arg1.target as SkillRuneItem;
                if (loc1.runeItemData) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.RuneRemove, loc1.runeItemData.uid));
                }
            }
            return;
        }

        /* internal  */showHandbookHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RuneShowRuneHandbook));
            return;
        }

        /* internal  */onRuneCompl(): void
        {
            this._generalRune1.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.GeneralRune1);
            this._generalRune2.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.GeneralRune2);
            this._generalRune3.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.GeneralRune3);
            this._generalRune4.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.GeneralRune4);
            this._skillRune1.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune1);
            this._skillRune2.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune2);
            this._skillRune3.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune3);
            this._skillRune4.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune4);
            this._skillRune5.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune5);
            this._skillRune6.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune6);
            this._skillRune7.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune7);
            this._skillRune8.runeBimtapdata = GlobalClass.getBitmapData(ImagesConst.SkillRune8);
            this.selectRuneItem(this._generalRune1);
            return;
        }

        /* internal  */createRuneItem(arg1: number, arg2: number, arg3: int, arg4: Boolean=false): SkillRuneItem
        {
            var loc1;
            (loc1 = new SkillRuneItem(arg3, arg4)).x = arg1;
            loc1.y = arg2;
            this.addChild(loc1);
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onRuneItemClick);
            this._vcSkillRune.push(loc1);
            return loc1;
        }

        /* internal  */onRuneItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as SkillRuneItem;
            this.selectRuneItem(loc1);
            return;
        }

        /* internal  */selectRuneItem(arg1: SkillRuneItem): void
        {
            if (this._currentSelectItem) 
            {
                this._currentSelectItem.selected = false;
            }
            this._currentSelectItem = arg1;
            arg1.selected = true;
            this.dispatchEvent(new SkillRuneEvent(SkillRuneEvent.RuneItemSelect, this._currentSelectItem));
            return;
        }

        public get currentSelectItem(): SkillRuneItem
        {
            return this._currentSelectItem;
        }

        public set selectIndex(arg1: int)
        {
            if (arg1 < 1 || arg1 > this._vcSkillRune.length) 
            {
                return;
            }
            var loc1=this._vcSkillRune[(arg1 - 1)];
            this.selectRuneItem(loc1);
            return;
        }

        public updateRuneData(): void
        {
            var loc1=null;
            var loc2=0;
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                this._generalRune1.runeItemData = null;
                this._generalRune2.runeItemData = null;
                this._generalRune3.runeItemData = null;
                this._generalRune4.runeItemData = null;
                loc1 = LadderCareerConfig.instance.getRuneListByCareer(Cache.instance.ladderBattlefield.ladderCareer);
                loc2 = 1;
                while (loc2 <= 12) 
                {
                    if (loc2 <= 8) 
                    {
                        SkillRuneItem(this["_skillRune" + loc2]).runeItemData = loc1[(loc2 - 1)];
                    }
                    else 
                    {
                        SkillRuneItem(this["_generalRune" + (loc2 - 8)]).runeItemData = loc1[(loc2 - 1)];
                    }
                    ++loc2;
                }
            }
            else 
            {
                this._generalRune1.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(1);
                this._generalRune2.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(2);
                this._generalRune3.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(3);
                this._generalRune4.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(4);
                this._skillRune1.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(5);
                this._skillRune2.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(6);
                this._skillRune3.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(7);
                this._skillRune4.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(8);
                this._skillRune5.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(9);
                this._skillRune6.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(10);
                this._skillRune7.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(11);
                this._skillRune8.runeItemData = Cache.instance.pack.runePackCache.getEnabledCareerItemDataByIndex(12);
            }
            if (this._currentSelectItem) 
            {
                this.dispatchEvent(new SkillRuneEvent(SkillRuneEvent.RuneItemSelect, this._currentSelectItem));
            }
            if (Cache.instance.rune.runeInfo) 
            {
                this.updateExtraNum(Cache.instance.rune.runeInfo);
            }
            return;
        }

        public updateExtraNum(arg1: SPlayerRuneInfo): void
        {
            var loc2=null;
            if (!arg1) 
            {
                return;
            }
            var loc1=0;
            while (loc1 < this._vcSkillRune.length) 
            {
                loc2 = this._vcSkillRune[loc1];
                if (loc2.runeType != ERuneType._ERuneTypeNormal) 
                {
                    if (loc2.runeType == ERuneType._ERuneTypeSkill) 
                    {
                        loc2.isLocked = loc1 - this.generalMaxNum >= arg1.skillExtraNum;
                    }
                }
                else 
                {
                    loc2.isLocked = loc1 >= arg1.normalExtraNum;
                }
                ++loc1;
            }
            return;
        }

        /* internal */ /* const */generalMaxNum: int=4;

        /* internal */ /* var */_generalRune1: SkillRuneItem;

        /* internal */ /* var */_generalRune2: SkillRuneItem;

        /* internal */ /* var */_generalRune3: SkillRuneItem;

        /* internal */ /* var */_generalRune4: SkillRuneItem;

        /* internal */ /* var */_skillRune1: SkillRuneItem;

        /* internal */ /* var */_skillRune2: SkillRuneItem;

        /* internal */ /* var */_skillRune3: SkillRuneItem;

        /* internal */ /* var */_skillRune4: SkillRuneItem;

        /* internal */ /* var */_skillRune5: SkillRuneItem;

        /* internal */ /* var */_skillRune6: SkillRuneItem;

        /* internal */ /* var */_skillRune7: SkillRuneItem;

        /* internal */ /* var */_skillRune8: SkillRuneItem;

        /* internal */ /* var */_btnSkillHandbook: GLoadedButton;

        /* internal */ /* var */_currentSelectItem: SkillRuneItem;

        /* internal */ /* var */_vcSkillRune: Vector.<SkillRuneItem>;
    }
